/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.MemberDao;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author zhang
 */
@WebServlet("/ls")
public class LoginServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String phone=req.getParameter("pname");
        String password=req.getParameter("passname");
        Boolean bool=new MemberDao().Login(phone,password);
        if(bool==true){
            HttpSession session=req.getSession();
            session.setAttribute("isLogin", "Y");
            String name=new MemberDao().getMemberNameByPhone(phone);
            session.setAttribute("username", name);
            resp.sendRedirect("index");
        }
        else{
            resp.setContentType("text/html;charset=utf-8");
            resp.getWriter().println("<h1>用户名或密码错误<br>或您已被禁用！！！</h1>");
            resp.getWriter().println("<a href='index'>返回首页</a>");
        }
    }
    
}
